<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <div class="app">obj.name</div>
</body>
<script>

    // getter 和 setter

    const obj = {
        _name: "admin",
        _age:18,
        app:document.querySelector(".app"),
        get name(){
            console.log("访问了name属性");
            // ...执行功能
            this.app.innerHTML = this._name;
            return this._name;
        },
        set name(val){
            console.log("修改了name属性", val)
            // ...执行功能
            this.app.innerHTML = val;
            this._name = val;
        }
    }

    // 访问对象的name属性
    // console.log(obj.name)
    
    // 控制对象的name属性
    // obj.name = "张三";

    // obj.name = "李四";
    
    // console.log(obj.name);

    obj.name

    
</script>
</html>